<template>
  <div>
    <nav-list></nav-list>
    <div class="message-board">
      <div class="subtitle"><span>{{ $t('navbar.message') }}</span></div>
      <div class="title">{{ $t('message.tip') }}：</div>
      <div class="message">
        <div class="name message-item"><span>{{ $t('message.name') }}：</span><input type="text" v-model="name"></div>
        <div class="email message-item"><span>{{ $t('message.email') }}：</span><input type="text" v-model="email"></div>
        <div class="sex message-item">
          <span>{{ $t('message.sex') }}：</span>
          <div class="sex-item" @click="sex = 'M'" :class="{active: sex == 'M'}">{{ $t('message.male') }}</div>
          <div class="sex-item" @click="sex = 'W'" :class="{active: sex == 'W'}">{{ $t('message.female') }}</div>
        </div>
        <div class="phone message-item"><span>{{ $t('message.contact') }}：</span><input type="text" v-model="phone"></div>
        <div class="company message-item"><span>{{ $t('message.company') }}：</span><input type="text" v-model="company"></div>
        <div class="content message-item">
          <span>{{ $t('message.content') }}：</span>
          <textarea v-model="text" placeholder="" maxlength="500"></textarea>
          <div class="tip">{{ $t('message.input') }}<span>{{500 - text.length}}</span>{{ $t('message.word') }}</div>
        </div>
        <button class="send-btn" @click="sendMessage()">{{ $t('message.submit') }}</button>
      </div>
    </div>
  </div>
</template>

<script>
  import navList from 'COMPS/nav-list.vue'
  export default {
    name: 'message-board',
    data() {
      return {
        name: '',
        sex: 'M',
        phone: '',
        email: '',
        company: '',
        text: ''
      }
    },
    components: {
      navList
    },
    methods: {
      sendMessage: function() {
        if(this.name == "" || this.sex == "" || this.phone == "" || this.email == "" || this.company == "" || this.text == "") {
          return alert('请填写完整信息');
        }
        console.log(this.name);
        console.log(this.sex);
        console.log(this.phone);
        console.log(this.email);
        console.log(this.company);
        console.log(this.text);
        let that = this;
        this.$axios.post('/pc.php/contact/addMessage', {
          real_name: that.name,
          email: that.email,
          content: that.text,
          gender: that.sex,
          address: that.company,
          phone: that.phone,
        }).then(res => {
          if(res.code == 200) {
            alert('留言成功');
            that.name = ''
            that.phone = ''
            that.email = ''
            that.company = ''
            that.text = ''
          }
        })
      }
    }
  }
</script>

<style lang="less">
  @import '~COMMON/common.less';
  .message-board {
    width: 880px;
    display: inline-block;
    .title {
      line-height: 50px;
      color: #666;
    }
    .message {
      padding-left: 65px;
      color: #666;
      .message-item {
        margin: 20px 0;
        >span {
        }
        >input[type="text"] {
          padding-left: 10px;
          width: 240px;
          height: 35px;
          border: 1px solid #dcdcdc;
          &:focus {
            outline: #006d60 solid 1px;
          }
          .On-xs({
            background-color: #f0f0f0;
            border: none;
          });
        }
        >input[type="radio"] {
          margin-left: 5px;
          vertical-align: middle;
        }
        >textarea {
          display: block;
          margin-top: 20px;
          margin-left: 20px;
          padding: 5px 10px;
          // vertical-align: top;
          font-size: 14px;
          width: 550px;
          height: 200px;
          resize: none;
          border: 1px solid #dcdcdc;
          &:focus {
            outline: #006d60 solid 1px;
          }
          .On-xs({
            box-sizing: border-box;
            width: 100%;
            margin: 0px;
            margin-top: 10px;
            border: none;
            background-color: #f0f0f0;
          });
        }
        &.name, &.email {
          margin: 0px;
          display: inline-block;
        }
        &.name {
          margin-right: 40px;
          .On-xs({
            margin-right: 0px;
            margin-bottom: 20px;
          });
        }
        &.sex {
          .sex-item {
            display: inline-block;  
            cursor: pointer;
            width: 80px;
            line-height: 32px;
            text-align: center;
            color: #666;
          }
          .active {
            color: #fff;
            background-color: #006d60;
          }
        }
      }
      .content {
        display: inline-block;
        position: relative;
        .tip {
          position: absolute;
          bottom: 10px;
          right: 5px;
          font-size: 12px;
          color: #666;
          >span {
            color: #006d60;
          }
        }
        .On-xs({
          display: block;
        });
      }
      .send-btn {
        display: block;
        cursor: pointer;
        font-size: 16px;
        border: none;
        outline: none;
        margin-left: 20px;
        color: #fff;
        width: 280px;
        height: 40px;
        background-color: #006d60;
        &:active {
          opacity: 0.8;
        }
        .On-xs({
          width: 100%;
          margin-left: 0px;
        });
      }
      .On-xs({
        color: #006d60;
        padding-left: 0px;
      });
    }
  }
</style>